package com.demo.controller;


import com.demo.entity.DischargeSummary;
import com.demo.entity.DischargeSummaryMedicine;
import com.demo.entity.Vo.DischargeSummaryVo;
import com.demo.entity.from.DischargeSummaryFrom;
import com.demo.mapper.DischargeSummaryMapper;
import com.demo.response.Result;
import com.demo.service.IDischargeSummaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出院总结表 前端控制器
 *
 * @author zm
 * @since 2020-12
 */
@Slf4j
@RestController
@RequestMapping("/dischargeSummary")
@Api(tags = "出院总结类")
public class DischargeSummaryController {
    @Autowired
    IDischargeSummaryService summaryService;


    @ApiOperation("新增出院总结")
    @PostMapping("/addDischargeSummary")
    public Result addDischargeSummary(@Validated @RequestBody DischargeSummaryFrom summaryFrom, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return Result.success(summaryService.addDischargeSummary(summaryFrom));
    }

    @ApiOperation("查询出院总结")
    @GetMapping("/dischargeSummaryList")
    public Result dischargeSummaryList(@RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                       @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "dischargeSummaryId", required = false) Integer dischargeSummaryId,
                                       @RequestParam(name = "patientId") Integer patientId) {
        return summaryService.dischargeSummaryList(pageNumber, pageSize, dischargeSummaryId, patientId);
    }

    @ApiOperation("更新出院总结")
    @PostMapping("/updateDischargeSummary")
    public Result updateDischargeSummary(@RequestBody DischargeSummaryFrom summaryFrom) throws Exception {
        return Result.success(summaryService.updateDischargeSummary(summaryFrom));
    }

    @ApiOperation(value = "出院总结--医生签字")
    @GetMapping("/dischargeSignature")
    public Result dischargeSignature(@RequestParam(name = "dischargeSummaryId") Integer dischargeSummaryId,
                                     @RequestParam(name = "userPass") String userPass) throws Exception {
        return Result.success(summaryService.dischargeSignature(dischargeSummaryId, userPass));
    }


}
